package com.gjy.concurrency.aotmic;

import com.gjy.util.ThreadUtil;
import org.junit.jupiter.api.Test;

import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.atomic.AtomicMarkableReference;
import java.util.concurrent.atomic.LongAdder;

/**
 * @author 宫静雨
 * @version 1.0
 * @since 2023-03-08 16:58:59
 */
public class Atomic4Test {

    @Test
    public void test2() {
        AtomicMarkableReference<String> reference = new AtomicMarkableReference<String>("", false);

        boolean e = reference.compareAndSet("", "E", false, true);
        System.out.println("e = " + e);

        System.out.println(reference.getReference());
    }

    @Test
    public void test1() {
        LongAdder longAdder = new LongAdder();

        ThreadPoolExecutor pool = ThreadUtil.defaultPool();
        for (long i = 0; i < 10000000L; i++) {
            pool.execute(longAdder::increment);
        }

        pool.shutdown();
        System.out.println("longAdder = " + longAdder);
    }
}
